﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LaughingDog.GameObjects;
using Microsoft.Xna.Framework.Media;
using LaughingDog.Managers;

namespace LaughingDog.Components
{
    /// <summary>
    /// A Music component is used for playing background music.
    /// </summary>
    public class Music : Component 
    {
        private Microsoft.Xna.Framework.Media.Song mSong;
        private String mAssetName = "";

        /// <summary>
        /// Gets or sets the file (.wma or .mp3) to use for the song.
        /// </summary>
        public String AssetName { get { return mAssetName; } set { mAssetName = value; mSong = AssetManager.Instance.Load<Song>(mAssetName); } }
        
        /// <summary>
        /// Creates a new instance of a Music component.
        /// </summary>
        /// <param name="gameObject">The GameObject that this component should be attached to.</param>
        public Music(GameObject gameObject)
            : base(gameObject)
        {                   
        }       

        /// <summary>
        /// Plays (or resumes) the Music component.
        /// </summary>
        public void Play()
        {
            if (mSong != null)
            {
                if (MediaPlayer.State == MediaState.Paused)
                    MediaPlayer.Resume();
                else
                    MediaPlayer.Play(mSong);
            }
        }

        /// <summary>
        /// Stops the playback of the Music component.
        /// </summary>
        public void Stop()
        {
            MediaPlayer.Stop();
        }

        /// <summary>
        /// Pauses the playback of the Music component.
        /// </summary>
        public void Pause()
        {
            MediaPlayer.Pause();
        }
    }
}
